<?php

namespace App\Repository;


use App\Models\Category;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

/**
 * Class CategoryRepository
 * @package App\Repository
 */
class CategoryRepository
{
    /**
     * @var Category
     */
    public $category;

    /**
     * CategoryRepository constructor.
     * @param $category
     */
    public function __construct(Category $category)
    {
        $this->category = $category;
    }

    /**
     * 获取所有分类
     * @return \Illuminate\Database\Eloquent\Collection|static[]
     */
    public function getAllCategories()
    {
        $categories = $this->category->with('iamges')->get();
        if ($categories->isEmpty()){
            throw new NotFoundHttpException('指定类目不存在，请检查参数', null, 50000);
        }
        return $categories;
    }
}